#include "currver.h"
#include "ui_currver.h"
#include <QTextStream>
#include <QFile>

CurrVer::CurrVer(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::CurrVer)
{
    bdf = BllDataFlow::getInstance();
    connect(bdf, &BllDataFlow::retranslateUiSignal, this, &CurrVer::retranslateUiSlot);
    ui->setupUi(this);

//    QString verFile = "/home/root/ver.txt";// QApplication::applicationDirPath()+"/ver.txt";
    QFile file(VerFile);
    if(!file.open(QIODevice::ReadOnly|QIODevice::Text))
    {
        //error
//        LOGFMTD("Can't find version file");
    }

    //... (open the file for reading, etc.)
    QTextStream textStream(&file);
    QString qVersion = textStream.readAll();

//    LOGFMTD("Current version text %s", qVersion.toStdString().c_str());
    QStringList verDetail = qVersion.split(".");
    if (verDetail.size() == 3)
    {
        //ok
        majorVer = verDetail.at(0).toInt();
        minorVer = verDetail.at(1).toInt();
        reviVer = verDetail.at(2).toInt();
    }
    else
    {
        majorVer = 1;
        minorVer = 0;
        reviVer = 0;
    }

    QString qVer = QString("%1 %2.%3.%4").arg(tr("Version: ")).arg(majorVer).arg(minorVer).arg(reviVer);
    ui->lblVer->setText(qVer);
}

CurrVer::~CurrVer()
{
    delete ui;
}

void CurrVer::retranslateUiSlot()
{
    ui->retranslateUi(this);
}
